package com.demo;



public class TestDemo {
    public static void main(String[] args) {
        int[] arr = {66,778,90,890,34,73,137};

        System.out.println(ArrSum(arr));

        int[] arr1 = {1,2,3,4,5};

        int[] arr2 = {1,2,3,4,5};

        boolean res = ArrayCompare(arr1,arr2);

        System.out.println(res?"数组完全相同":"数组不相同");

        System.out.println("---------------");

        int[] arr3 = {30,40,55,68,90,102,490};

        System.out.println(ArrayIndexOf(arr3,55));
        System.out.println(ArrayIndexOf(arr3,515));

        System.out.println("---------------");

        ArrayDemo.printArr(ArrayReserve(arr3));

    }
    //练习数组求和特定的数组求和
    public static int ArrSum(int[] arr){
        int sum = 0;

        if(arr.length<=0){
            return sum;
        }
        //判断数组循环的值，个位数和十位数是什么？
        for (int i =0;i<arr.length;i++){
            if(arr[i] % 2 == 0 && arr[i]%10 != 7 && arr[i]/10%10!=7){
                System.out.println(arr[i]);
                sum += arr[i];
            }
        }

        return sum;
    }

    //比较数组的内容是否相同
    public static boolean ArrayCompare(int[] arr1,int[] arr2){
        boolean isSame = true;

        if(arr1.length != arr2.length){
            isSame = false;
            return isSame;
        }

        //循环判断两个数组是否相同
        for(int i =0;i<arr1.length;i++){
            //只要有一个不相同的，那么数组就直接返回false
            if(arr1[i] != arr2[i]){
                isSame = false;
                break;
            }
        }

        return isSame;
    }
    //查找判断一个数组是否存在封装函数
    public static int ArrayIndexOf(int[] arr,int number){
//        boolean isFind = false;
        int index = -1;

        if(arr.length<=0){
            return index;
        }
        //循环判断内容
        for(int i =0;i<arr.length;i++){
            if(arr[i] == number){
                index = i;
                break;
            }
        }

        return index;
    }

    public static int[] ArrayReserve(int[] arr){
        //定义开始位置和结束位置，开始位置不能小于结束位置，训话条件
        for (int start = 0,end = arr.length-1;start<=end;start++,end--){
            //交换变量的内容
            int tmp = arr[start];
            arr[start] = arr[end];
            arr[end] = tmp;
        }

        return arr;
    }
}
